Conversation
c595750 to
846bce4
Compare
a52146d to
ab12f21
Compare
ab12f21 to
d17b922
Compare
e4af58a to
1ebf3c5
Compare
1ebf3c5 to
52dd7d8
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #75 +/- ##
==========================================
+ Coverage 76.88% 77.81% +0.92%
==========================================
Files 14 15 +1
Lines 398 613 +215
==========================================
+ Hits 306 477 +171
- Misses 92 136 +44 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
695c683 to
ff834f7
Compare
f3e2907 to
480df1f
Compare
2468d6c to
a734808
Compare
a629c59 to
66e8edc
Compare
74685a6 to
be505db
Compare
| lines = post.content.strip().splitlines() | ||
| new_content = lines[0] if lines else '' |
There was a problem hiding this comment.
Correctness: In _process_content, the first line of content is now always preserved when remove_content is True, even if keep_first_header is False. This makes the flag ineffective and results in unintended content retention. Initialize new_content to an empty string and only assign lines[0] if keep_first_header is True.
🤖 AI Agent Prompt for Cursor/Windsurf
📋 Copy this prompt to your AI coding assistant (Cursor, Windsurf, etc.) to get help fixing this issue
File: foliant/partial_copy.py. Lines 253-259. Issue: keep_first_header=False no longer removes content because the first line is always preserved. Fix by only retaining the first line when keep_first_header is true, and handle header concatenation safely when new_content is empty. Apply the provided diff.
| import os | ||
| import re | ||
| from pathlib import Path | ||
| from shutil import copy | ||
| from typing import Union, List, Set | ||
| import frontmatter |
There was a problem hiding this comment.
Duplicate Code:
This function extract_first_header duplicates existing code.
📍 Original Location:
foliant/preprocessors/_unescape.py:21-39
Function: process_escaped_tags
💡 Recommendation:
Consider consolidating into a unified content processing utility class or module. Both functions could be methods in a MarkdownContentProcessor class that handles various markdown text operations (extraction, transformation, parsing). The extract_first_header method could use a similar compiled pattern approach as process_escaped_tags for consistency and performance. Alternatively, create a shared base function that handles regex pattern matching on markdown content, with parameters to control whether to extract (search/match) or transform (substitute). This would reduce code duplication in the regex pattern handling and content processing logic.
Consider importing and reusing the existing function instead of duplicating the logic.
There was a problem hiding this comment.
Thank you for the analysis, but this appears to be a false positive. The functions are not duplicate code:
-
Different purpose:
process_escaped_tags— transformation (removes<from escaped tags)_extract_first_header— extraction (finds and returns the first header)
-
Different regex patterns:
self.pattern(inprocess_escaped_tags) — specific to escaped tags, defined in__init__r'^(#{1,6})\s+(.+)$'(in_extract_first_header) — for finding Markdown headers
-
Different signatures and context:
process_escaped_tags— instance method, usesself, includes logging_extract_first_header— static utility method
The ~81% similarity is likely due to the shared high-level structure of "apply regex to string" — but this is the abstraction level of "a function that works with regexes," not duplication of business logic.
Merging these into one class would introduce unnecessary complexity and violate the Single Responsibility Principle. If any optimization is needed, it would be extracting regex compilation to module-level constants — not merging the functions.
Workflows:
Base Foliant backend:
partial_copymethod, which copies files according to a given listCLI:
prepare_list_of_filesmethod, which prepares a list of files from a user-specified stringUtils:
Other